package urlconfig;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author 01395265
 * @date 2020/7/27
 */
public class TestCollation {

    public static void main(String[] args) throws Exception {
        String sqlCi = "select * from date_url_test_cs where name_ci = 'e'";
        String sqlCs = "select * from date_url_test_cs where name_cs = 'e'";
        query(sqlCi);

        System.out.println("-------------------------");

        query(sqlCs);
    }

    public static void query(String sql) throws Exception {

        Connection connection = getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        ResultSet resultSet = preparedStatement.executeQuery();

        while (resultSet.next()) {
            String nameCi = (String) resultSet.getObject("name_ci");
            String nameCS = (String) resultSet.getObject("name_cs");
            System.out.println(nameCi + ", " + nameCS);
        }
    }

    private static Connection getConnection() {
        try {
            DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        try {
            return DriverManager.getConnection("jdbc:mysql://10.88.26.129:3306/auth?collationConnection=utf8mb4_0900_ai_ci", "authopr", "authopr#1q2s");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

}
